---
author: " "
date: ' '
title: 'Analysis Code: Race, Voice, and Authority in Discussion Groups'
output: 
  pdf_document:
    toc: true
header-includes:
   - \usepackage{booktabs}
   - \usepackage{floatrow}
   - \floatsetup[figure]{capposition=top}
   - \floatsetup[table]{capposition=top}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```

```{r load}
# prevent from using scientific notation for preferences
options(scipen=10)

# load packages
library(pacman)
p_load(here, dplyr, ggplot2, stringr, modelsummary, cowplot, stargazer,
       bit64, gridExtra, estimatr, tidyr, kableExtra, MatchIt, ggpubr, clubSandwich)
i_am("Code/05_analyses.Rmd")

tab1 <- read.csv(here("Data", "tab1.csv"))
tab2 <- read.csv(here("Data", "tab2.csv"))

# recode race categories
tab1$whites_cat <- relevel(factor(tab1$whites_cat), ref="Less than 5 whites")
tab2$whites_cat <- relevel(factor(tab2$whites_cat), ref="Less than 5 whites")

```



## Main text models


<!-- Table 1: Length of Speech (in words) -->

```{r}
# regress length on race, add in other predictors

mod1 <- lm_robust(log(length+1)~white+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(length+1)~white*whites_cat, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(length+1)~white+type+ordinal_pref+distance+num_others_pref, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust(log(length+1)~white+type+ordinal_pref+distance+num_others_pref+fore+log(total_words_attr_round-length+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)


```

```{r, results='asis'}

# export results to latex  
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(13, 18, 21:24)

modelsummary(list("Base Model"=mod1, "Pref. Control"=mod3, "Endog. Controls"=mod4, "Interaction"=mod2), 
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
               "distance"="Pref. Distance",
               "num_others_pref" = "Others Sharing Pref.",
               "fore"="Foreperson",
               #"typeScale"="Outcome: Scale",
               "log(total_words_attr_round - length + 1)"="Total Group Speech Length",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites"="White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Length of Speech (in words) \\label{tab:juror_length}", 
             add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
      column_spec(2:5,width=".7in") %>%
      row_spec(13, italic = T) %>%
      row_spec(18, italic = T)

# Uncomment the lines below to calculate the predicted speech length at different covariate values:

#mod1 <- lm(log(length+1)~white+type+factor(scenario), 
#          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8))
#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "type"="Scale", "scenario"=7))))+1
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "type"="Scale", "scenario"=7))))+1
#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "whites_cat"="5 whites", "total_words_attr_round"=2123, "length"=308, "fore"=0, #"type"="Scale", "scenario"=7))))
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "whites_cat"="5 whites", "total_words_attr_round"=2123, "length"=308, "fore"=0, #"type"="Scale", "scenario"=7))))

```


<!-- Table 2: Deliberator Mentions of Any Preference -->

    ```{r}
    # regress total number of times a juror mentions a preference 
mod1 <- lm_robust(log(total_pref_mentions+1)~white+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(total_pref_mentions+1)~white*whites_cat+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(total_pref_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust(log(total_pref_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref+fore+log(length+1),  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}

# export results to latex 
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(13, 18, 21:24)

modelsummary(list("Base Model"=mod1,"Preference Control"=mod3, "Endog. Control"=mod4, "Interaction"=mod2),
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
               "log(total_pref_mentions + 1)"="Total Pref. Mentions",
                              "distance"="Pref. Distance",
               "num_others_pref"="Others Sharing Pref.",
               "log(length + 1)"="Total Indiv. Speech",
               "fore"="Foreperson",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites" = "White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Deliberator Mentions of Any Preference \\label{tab:any_pref}", add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(13, italic = T) %>%
      row_spec(18, italic = T)


#rm(mod1, mod2, mod3, mod4)
```


<!-- Table 3: Position of First Speech Turn (Distance from Beginning of Deliberation) -->

```{r}

# regress position of first turn on race, add other variables
mod1 <- lm_robust((log(first_turn+1)*-1)~white+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust((log(first_turn+1)*-1)~white*whites_cat+scale, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(first_turn+1)*-1)~white+type+ordinal_pref+distance+num_others_pref, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust((log(first_turn+1)*-1)~white+type+ordinal_pref+distance+num_others_pref+fore+log(total_turns+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(13, 18, 21:23)

modelsummary(list("Base Model"=mod1,"Preference Control"=mod3, "Endog. Control"=mod4,  "Interaction"=mod2),
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
                "num_others_pref"="Others Sharing Pref.",
               "distance"="Pref. Distance",
               "fore"="Foreperson",
               "log(total_turns + 1)"="Total Group Speech Length", 
                "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites"="White x 5-White Group"),
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Position of First Speech Turn (Distance from Beginning of Deliberation) \\label{tab:juror_first}", 
             add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(13, italic = T) %>%
      row_spec(18, italic = T)


# Uncomment the lines below to get predicted turn position at different covariate values:

#mod1 <- lm((log(first_turn+1)*-1)~white+whites_cat+log(total_turns+1)+fore+type+scenario, 
#          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8))
#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "whites_cat"="5 whites", "total_turns"=212, "fore"=0, "type"="Scale", "scenario"=7)))*-1)
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "whites_cat"="5 whites", "total_turns"=212, "fore"=0, "type"="Scale", "scenario"=7)))*-1)

```

<!-- Table 4: Position of Last Speech Turn (Distance from End of Deliberation) -->

```{r}

# regress last turn position on race, other variables:
mod1 <- lm_robust((log(total_turns-last_turn+1)*-1)~white+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust((log(total_turns-last_turn+1)*-1)~white*whites_cat+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(total_turns-last_turn+1)*-1)~white+type+ordinal_pref+distance+num_others_pref, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust((log(total_turns-last_turn+1)*-1)~white+type+ordinal_pref+distance+num_others_pref+fore+log(total_turns+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(13, 18, 21:24)

modelsummary(list("Base Model"=mod1, "Preference Control"=mod3, "Endog. Control"=mod4, "Interaction"=mod2),
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
               "distance"="Pref. Distance",
                "num_others_pref"="Others Sharing Pref",
               "fore"="Foreperson",
               "log(total_turns + 1)"="Total Group Speech Length",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites"="White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001), 
             title = "Position of Last Speech Turn (Distance from End of Deliberation) \\label{tab:juror_last}", add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(13, italic = T) %>%
      row_spec(18, italic = T)

# Uncomment lines below to get predicted turn position at different covariate values:

#mod1 <- lm((log(total_turns-last_turn+1)*-1)~white+type+factor(scenario), 
#          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8))
#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "type"="Scale", "scenario"=7)))*-1)+1
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "type"="Scale", "scenario"=7)))*-1)+1

#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "whites_cat"="5 whites", "total_turns"=212, "fore"=0, "type"="Scale", "scenario"=7)))*-1)
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "whites_cat"="5 whites", "total_turns"=212, "fore"=0, "type"="Scale", "scenario"=7)))*-1)

```


<!-- Table 5: Number of Group Mentions of Indiv. Preference -->

```{r}
# regress number of times jury mentions juror's preference on race, other variables
mod1 <- lm_robust(log(pref_mentions+1)~white+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(pref_mentions+1)~white*whites_cat+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(pref_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust(log(pref_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref+log(total_mentions-pref_mentions+1),  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)


```

```{r, results='asis'}
# export results to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(11, 16, 19:22)

modelsummary(list("Base Model"=mod1, "Preference Control"=mod3, "Endog. Controls"=mod4, "Interaction"=mod2),
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref" = "Preference",
               "distance"="Pref. Distance",
                "num_others_pref"="Others Sharing Pref.",
              "log(total_mentions - pref_mentions + 1)"="Total Pref. Mentions",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites"="White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Number of Group Mentions of Indiv. Preference \\label{tab:juror_prefmens}", add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(11, italic = T) %>%
      row_spec(16, italic = T)


# Uncomment lines below to get predicted number of mentions for different covariate values:

#mod1 <- lm(log(pref_mentions+1)~white+scale+factor(scenario),  
#          data=tab2 %>% filter(round==1))
#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "scale"="scale", "scenario"=7))))+1
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "scale"="scale", "scenario"=7))))+1

#exp(predict(mod1, newdata=as.data.frame(list("white"=1, "whites_cat"="5 whites", "total_mentions"=23, "num_others_pref"=0, "pref_mentions"=5, #"fore"=0, "scale"="scale", "scenario"=7))))
#exp(predict(mod1, newdata=as.data.frame(list("white"=0, "whites_cat"="5 whites", "total_mentions"=23,"num_others_pref"=0, "pref_mentions"=5, #"fore"=0, "scale"="scale", "scenario"=7))))
```

<!-- Figure 1: Group decision by group's most-mentioned preference -->

```{r}

preftab <- tab2 %>% 
  filter(!is.na(jryscale)) %>%
  filter(scale=="scale") %>%
  filter(jryscale %in% c(0,1,2,3,4,5,6,7,8)) %>%
  group_by(jurynum, own_pref, jryscale) %>%
  summarize(mens=sample(pref_mentions, 1)) 

preftab <- preftab %>%
  group_by(jurynum, jryscale) %>%
  summarize(n_max = max(mens),
            max = own_pref[mens==max(mens)],
            tot = sum(mens)) 
table(preftab$jryscale==preftab$max)
table(preftab$jryscale>=(preftab$max-1)&preftab$jryscale<=(preftab$max+1))

a <- ggplot(preftab) +
  geom_jitter(aes(x=max, y=jryscale), width = .2, height=.2) +
  theme_bw() + theme(text=element_text(size=20)) +
  xlab("Group's Most-Mentioned Preference") + ylab("Group Decision") +
  geom_smooth(aes(x=max, y=jryscale), se=FALSE) + 
  geom_abline(slope=1, intercept=0)


#pdf("pref_verdict2.pdf")
a
#dev.off()

```


<!-- Table 6: Number of Times Focal Person's Preference is Mentioned by Specific Members -->

    ```{r}
    
    # regressions using mentions of preferences by self, others, foreperson
mod0 <- lm_robust(log(own_pref_mentions+1)~white+whites_cat+num_others_pref+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod1 <- lm_robust(log(own_pref_mentions+1)~white+whites_cat+log(total_pref_mentions - own_pref_mentions +1)+num_others_pref+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(other_pref_mentions+1)~white+whites_cat+log(total_other_pref_mentions+1)+num_others_pref+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(fore_pref_mentions+1)~white+whites_cat+log(fore_total_mentions+1)+num_others_pref+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}

# export to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod0 = c("", "X", "Group", mod0$nclusters),
mod1 = c("", "X", "Group", mod1$nclusters),
mod2 = c("", "X", "Group", mod2$nclusters),
mod3 = c("", "X", "Group", mod3$nclusters)
)
attr(add_rows, "position") = c(3, 12:15)

modelsummary(list("Own Mentions- Raw"=mod0, "Own Mentions"=mod1, "Others' Mentions"=mod2, "Forep. Mentions"=mod3), output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "ordinal_pref"="Preference",
               "white:whites_cat5 whites" = "White Indiv. x 5 Whites",
               "log(total_pref_mentions - own_pref_mentions + 1)"="Total Pref. Mentions",
               "log(total_other_pref_mentions + 1)"="Total Pref. Mentions",
               "log(fore_total_mentions + 1)"="Total Pref. Mentions",
               "num_others_pref"="Others Sharing Pref."), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Number of Times Focal Person's Preference is Mentioned by Specific Members \\label{tab:juror_indivpref}", 
             add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(3, italic = T)


#rm(mod1, mod2, mod3, mod4)
```


<!-- Figure 2: Predicted mentions of a person's preference by others in their group -->

```{r}
# predictions manually input from calculations in sdi_do

fig_tab <- as.data.frame(rbind(c(0, "none", 1.51, .172),
                     c(0, ".5 to 1", 1.22, .152),
                     c(0, "1.5 to 2.5", 1.33, .109),
                     c(0, "3+", .892, .187),
                     c(1, "none", 1.23, .127),
                     c(1, ".5 to 1", 1.28, .076),
                     c(1, "1.5 to 2.5", 1.25, .075),
                     c(1, "3+", 1.19, .081)))
colnames(fig_tab) <- c("white", "distance", "pred", "se")
fig_tab$distance <- factor(fig_tab$distance, levels=c("none", ".5 to 1", "1.5 to 2.5", "3+"), ordered=TRUE)
fig_tab <- fig_tab %>% mutate(across(c(pred, se), as.numeric))
fig_tab <- fig_tab %>% mutate(white = case_when(white==0~"POC",
                                                white==1~"White"))

#pdf("pred_intx.pdf", width=10, height=5)
ggplot(fig_tab) +
  geom_bar(aes(x=factor(white), y=pred, fill=distance), stat="identity", position="dodge", color="black") +
  theme_bw() + 
  xlab("Indiv. Race") + ylab("Predicted Mentions of Pref") +
  scale_fill_manual(name="Pref. Distance from Median", labels=c("0", ".5 to 1", "1.5 to 2.5", "3+"), values=c("black", "gray70", "gray90", "white")) +
  theme(text=element_text(size=15))
#dev.off()

```


<!-- Figure 3: Summary of Key Results -->

```{r, fig.width=15, fig.height=15}

# Values below were manually input from the file sdi_do
  # for each variable, record the predicted values for white/POC and high/low confidence intervals

pred_dat=as.data.frame(list("white"=c(0,1),
                            "length"=c(144.495, 260.879),
                            "length_hi"=c(169.338, 288.900),
                            "length_lo"=c(119.653, 232.859)))

pred_dat$total_pref_mentions <- c(3.111, 4.351)
pred_dat$total_pref_mentions_hi <- c(3.343, 4.561)
pred_dat$total_pref_mentions_lo <- c(2.878, 4.142)

pred_dat$first_turn <- c(-8.587, -6.478)
pred_dat$first_turn_hi <- c(-9.601, -6.902)
pred_dat$first_turn_lo <- c(-7.573, -6.154)

pred_dat$last_turn <- c(-14.583, -10.319)
pred_dat$last_turn_hi <- c(-16.560, -10.942)
pred_dat$last_turn_lo <- c(-12.607, -9.695)

pred_dat$pref_mentions <- c(5.120, 6.079)
pred_dat$pref_mentions_hi <- c(5.496, 6.300)
pred_dat$pref_mentions_lo <- c(4.743, 5.859)

pred_dat$own_pref_mentions <- c(2.122, 2.574)
pred_dat$own_pref_mentions_hi <- c(2.295, 2.684)
pred_dat$own_pref_mentions_lo <- c(1.948, 2.463)

pred_dat$other_pref_mentions <- c(3.386, 3.456)
pred_dat$other_pref_mentions_hi <- c(3.750, 3.665)
pred_dat$other_pref_mentions_lo <- c(3.022, 3.247)

pred_dat$fore_pref_mentions <- c(2.471, 2.686)
pred_dat$fore_pref_mentions_hi <- c(2.723, 2.829)
pred_dat$fore_pref_mentions_lo <- c(2.219, 2.541)

pred_dat$other_intx <- c(2.484, 3.306)
pred_dat$other_intx_hi <- c(2.798, 3.487)
pred_dat$other_intx_lo <- c(2.170, 3.124)

# reshape data for plotting
tab3 <- pred_dat %>% 
  pivot_longer(cols=c(length, total_pref_mentions, first_turn, last_turn, 
                      pref_mentions, own_pref_mentions, other_pref_mentions, 
                      fore_pref_mentions, other_intx)) %>%
  select(white, name, value) %>%
  full_join(pred_dat %>%
  pivot_longer(cols=c(length_lo, total_pref_mentions_lo, first_turn_lo, last_turn_lo, 
                      pref_mentions_lo, own_pref_mentions_lo, other_pref_mentions_lo, 
                      fore_pref_mentions_lo, other_intx_lo),
               names_to="name", values_to="conf_lo") %>%
    mutate(name = str_remove(name, "_lo")) %>%
    select(white, name, conf_lo)
  ) %>%
    full_join(pred_dat %>%
  pivot_longer(cols=c(length_hi, total_pref_mentions_hi, first_turn_hi, last_turn_hi, 
                      pref_mentions_hi, own_pref_mentions_hi, other_pref_mentions_hi, 
                      fore_pref_mentions_hi, other_intx_hi),
               names_to="name", values_to="conf_hi") %>%
    mutate(name = str_remove(name, "_hi")) %>%
    select(white, name, conf_hi)
  ) %>% 
  mutate(white = recode(white, "0"="POC", "1"="White")) %>%
  mutate(name = recode(name,
                       length="Speech Length", 
                       total_pref_mentions="Mentions of Any Pref.",
                       first_turn="First Turn: Distance from Beg.",
                       last_turn="Last Turn: Distance from End",
                       pref_mentions="Total Mentions of Indiv. Pref.",
                       own_pref_mentions="Own Mentions of Indiv. Pref.",
                       fore_pref_mentions="Forep. Mentions of Indiv. Pref.",
                       other_pref_mentions="Others' Mentions of Indiv. Pref.",
                       other_intx="Other Mens.: 3+ from Median",)) %>%
  mutate(name=factor(name,
                     levels=c("Speech Length","Mentions of Any Pref.",
                              "First Turn: Distance from Beg.","Last Turn: Distance from End",
                              "Total Mentions of Indiv. Pref.","Own Mentions of Indiv. Pref.",
                              "Forep. Mentions of Indiv. Pref.",
                              "Others' Mentions of Indiv. Pref.", "Other Mens.: 3+ from Median"),
                     ordered=TRUE))

# plot panels for each outcome
a <- ggplot(tab3 %>% filter(name %in% c("Speech Length","Mentions of Any Pref."))) +
  geom_bar(aes(x=factor(white), y=value), stat="identity") +
  geom_errorbar(aes(x=factor(white), ymin=conf_lo, ymax=conf_hi), width=.2) +
  facet_wrap(~name, scales="free", nrow=1) +
  theme_bw() + 
  xlab("Juror Race") + ylab("Predicted Value") +
  theme(text=element_text(size=25), axis.title.x=element_blank()) 

b <- ggplot(tab3 %>% 
         filter(name=="First Turn: Distance from Beg.") %>% 
         mutate(white = case_when(white=="POC"~0, white=="White"~1))) +
  geom_rect(aes(xmin=white-.45,xmax=white+.45,
               ymin=-15, ymax=value)) +
  geom_errorbar(aes(x=white, ymin=conf_lo, ymax=conf_hi), width=.2) +
  scale_x_continuous(breaks=c(0,1), labels=c("POC", "White")) +
  scale_y_continuous(labels = function(x) sprintf("%.0f", x)) +
  facet_wrap(~name, scales="free", nrow=1) +
  theme_bw() + 
  xlab("Juror Race") + 
  theme(text=element_text(size=25), plot.margin = unit(c(0, 0, 0, 0), "cm"),
        axis.title.y=element_blank(), axis.title.x=element_blank()) 

c <- ggplot(tab3 %>% 
         filter(name=="Last Turn: Distance from End") %>% 
         mutate(white = case_when(white=="POC"~0, white=="White"~1))) +
  geom_rect(aes(xmin=white-.45,xmax=white+.45,
               ymin=-20, ymax=value)) +
  geom_errorbar(aes(x=white, ymin=conf_lo, ymax=conf_hi), width=.2) +
  scale_x_continuous(breaks=c(0,1), labels=c("POC", "White")) +
  facet_wrap(~name, scales="free", nrow=1) +
  theme_bw() + ylab("Predicted Value") +
  theme(text=element_text(size=25), plot.margin = unit(c(0, 0, 0, 0), "cm"),
         axis.title.x=element_blank()) 

d <- ggplot(tab3 %>% filter(name %in% c( "Own Mentions of Indiv. Pref.", "Total Mentions of Indiv. Pref."))) +
  geom_bar(aes(x=factor(white), y=value), stat="identity") +
  geom_errorbar(aes(x=factor(white), ymin=conf_lo, ymax=conf_hi), width=.2) +
  facet_wrap(~name, scales="free", nrow=1) +
  theme_bw() + 
  xlab("Juror Race") + 
  theme(text=element_text(size=25), axis.title.x=element_blank(), axis.title.y=element_blank()) 

f <- ggplot(tab3 %>% filter(name %in% c("Forep. Mentions of Indiv. Pref.",
                              "Others' Mentions of Indiv. Pref.", "Other Mens.: 3+ from Median"))) +
  geom_bar(aes(x=factor(white), y=value), stat="identity") +
  geom_errorbar(aes(x=factor(white), ymin=conf_lo, ymax=conf_hi), width=.2) +
  facet_wrap(~name, scales="free", nrow=1) +
  theme_bw() + 
  xlab("Juror Race") + ylab("Predicted Value") +
  theme(text=element_text(size=25)) 


# combine panels and export

#pdf("summary_fig.pdf", width=15, height=15)
first_row <- plot_grid(a, b, nrow=1, rel_widths=c(2,1))
second_row <- plot_grid(c, d, nrow=1, rel_widths=(c(1,2)))
plot_grid(first_row, second_row, f, nrow=3)
#dev.off()

```


## Appendix Models

<!-- Tables S1 and S2: Sample Composition -->

```{r, results='asis'}
stargazer(as.data.frame(tab2 %>%
            filter(round==1) %>%
            ungroup %>%
            mutate(sex_f = sex=="F",
                   age_y = age=="18-39", 
                   age_m = age=="40-59",
                   age_o = age=="60+", 
                   ed_hs = educ=="HS or less",
                   ed_sc = educ=="Some coll.",
                   ed_ba = educ=="BA or more",
                   inc_l = income=="30k or less",
                   inc_m = income=="30-50k",
                   inc_h = income=="more than 50k", 
                   pref = ordinal_pref) %>%
            select(white, sex_f, age_y, age_m, age_o, ed_hs, ed_sc, ed_ba, inc_l, inc_m, inc_h, pref)),
          type = "latex",
          digits = 2,
          summary.stat = c("n", "mean", "sd", "min", "max"),
          title = "Key Variable Summary Statistics (Individual-Level, All Juries)",
          covariate.labels = c("Race: White", "Female", "Younger (18-29)", "Middle Age (30-59)", "Older (60+)", "High School", "Some College", "College Graduate", "Low Income (< 30K)", "Middle Income (30-50K)", "High Income (> 50K)", "Pre-Deliberation Punishment Preference"))

stargazer(as.data.frame(tab2 %>%
            filter(round==1) %>%
            group_by(jurynum) %>%
            summarize(f = sum(sex=="F"),
                      w = sum(white),
                   age_y = sum(age=="18-39"), 
                   age_m = sum(age=="40-59"),
                   age_o = sum(age=="60+"), 
                   ed_hs = sum(educ=="HS or less"),
                   ed_sc = sum(educ=="Some coll."),
                   ed_ba = sum(educ=="BA or more"),
                   inc_l = sum(income=="30k or less"),
                   inc_m = sum(income=="30-50k"),
                   inc_h = sum(income=="more than 50k"), 
                   pref = median(ordinal_pref, na.rm=T),
                   sd = sd(ordinal_pref, na.rm=T))) %>%
            select(f:sd),
          type = "latex",
          digits = 2,
          summary.stat = c("n", "mean", "sd", "min", "max"),
          title = "Key Variable Summary Statistics (Group-Level, All Groups)",
          covariate.labels = c("Number of Women", "Number of Whites", "Number Younger", "Number Mid-Age", "Number Older", "Number HS Grad or Less", "Number Some Coll.", "Number College Grads", "Number Low Income", "Number Mid-Income", "Number High Income",  "Median Pre-Deliberation Prefs (Round 1)", "SD Pre-Delib Prefs (Round 1)"))
```


<!-- Figure S1: Jury Racial Composition -->

``` {r}

jury_race1 <- ggplot(tab2 %>% distinct(jurynum, .keep_all=TRUE), aes(as.factor(nonwhites)))+
  geom_bar(width=.5,position=position_dodge(width = .5), size = 3)+
  theme_bw()+
  theme(legend.position = "none")+
  stat_count(aes(label=..count..), vjust=-0.2,
             geom="text", position=position_dodge(width = .5))+
  labs(x="Number of POC in Jury",y="Count",
       title="All Juries with Identified Transcripts")+
  geom_vline(xintercept=c(1.5,2.5), linetype="dashed")


jury_identify <- tab1 %>%
  filter(round==1&jury_prop_words_attributed>.8) %>%
  group_by(jurynum) %>%
  summarise(
    whites = mean(whites, na.rm = TRUE),
    nonwhites = 6 - mean(whites, na.rm = TRUE)
  )

jury_race2 <- ggplot(jury_identify, aes(as.factor(nonwhites)))+
  geom_bar(width=.5,position=position_dodge(width = .5), size = 3)+
  theme_bw()+
  theme(legend.position = "none")+
  stat_count(aes(label=..count..), vjust=-0.2,
             geom="text", position=position_dodge(width = .5))+
  labs(x="Number of POC in Jury",y="Count",
       title="Juries with Individually-Identified Speakers")+
  geom_vline(xintercept=c(1.5,2.5), linetype="dashed")

combined_plot <- ggarrange(
  jury_race1, jury_race2,
  labels = c("A", "B"),  # Label each plot
  ncol = 1, nrow = 2    # Arrange plots in 2 rows and 1 column
  )

combined_plot <- annotate_figure(
  combined_plot,
  bottom = text_grob("Note: Juries with individually-identified speakers restricted to groups for which at least 80% of the words are attributed to an identified speaker.", size = 10)
)

combined_plot

rm(jury_race1, jury_race2)


```


<!-- Figure S2: Juror Attributes -->

```{r composition,  fig.height=4, fig.width=15, fig.cap="&nbsp;"}

tab2 <- left_join(tab2, tab1 %>% select(case_id, round, length))

tab2 %>%
  summarize(n=n(),
            n_id = sum(!is.na(Identifier)), 
            n_speak = sum(length>0, na.rm=T),
            tot=sum(white, na.rm=T),
            id = sum(white==1&!is.na(Identifier)),
            speak = sum(white==1&length>0, na.rm=T)) %>%
  mutate(group = "White") %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(white==0, na.rm=T),
                        id = sum(white==0&!is.na(Identifier), na.rm=T),
                        speak = sum(white==0&length>0, na.rm=T)) %>%
              mutate(group = "Nonwhite")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(sex=="F", na.rm=T),
                        id = sum(sex=="F"&!is.na(Identifier), na.rm=T),
                        speak = sum(sex=="F"&length>0, na.rm=T)) %>%
              mutate(group = "Female")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(sex=="M", na.rm=T),
                        id = sum(sex=="M"&!is.na(Identifier), na.rm=T),
                        speak = sum(sex=="M"&length>0, na.rm=T)) %>%
              mutate(group = "Male")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(educ=="HS or less", na.rm=T),
                        id = sum(educ=="HS or less"&!is.na(Identifier), na.rm=T),
                        speak = sum(educ=="HS or less"&length>0, na.rm=T)) %>%
              mutate(group = "<=HS grad")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(educ=="Some coll.", na.rm=T),
                        id = sum(educ=="Some coll."&!is.na(Identifier), na.rm=T),
                        speak = sum(educ=="Some coll."&length>0, na.rm=T)) %>%
              mutate(group = "Some coll.")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(educ=="BA or more", na.rm=T),
                        id = sum(educ=="BA or more"&!is.na(Identifier), na.rm=T),
                        speak = sum(educ=="BA or more"&length>0, na.rm=T)) %>%
              mutate(group = ">=BA")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(age=="18-39", na.rm=T),
                        id = sum(age=="18-39"&!is.na(Identifier), na.rm=T),
                        speak = sum(age=="18-39"&length>0, na.rm=T)) %>%
              mutate(group = "18-39")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(age=="40-59", na.rm=T),
                        id = sum(age=="40-59"&!is.na(Identifier), na.rm=T),
                        speak = sum(age=="40-59"&length>0, na.rm=T)) %>%
              mutate(group = "40-59")) %>%
  bind_rows(tab2 %>%
              summarize(n=n(),
                        n_id = sum(!is.na(Identifier)), 
                        n_speak = sum(length>0, na.rm=T),
                        tot=sum(age=="60+", na.rm=T),
                        id = sum(age=="60+"&!is.na(Identifier), na.rm=T),
                        speak = sum(age=="60+"&length>0, na.rm=T)) %>%
              mutate(group = "60+")) %>%
  mutate(prop_total = tot/n) %>%
  mutate(prop_ided = id/n_id) %>%
  mutate(prop_speak = speak/n_speak) %>%
  select(group:prop_speak) %>%
  pivot_longer(cols = contains("prop"), names_to = "Quantity", names_prefix = "prop_", values_to = "prop") %>%
  mutate(group = factor(group, levels=c("Female", "Male", "White", "Nonwhite",
                                        "18-39", "40-59", "60+",
                                        "<=HS grad", "Some coll.", ">=BA"), ordered=T)) %>%
  mutate(Quantity = recode(Quantity, ided="Prop. of Identified Jurors", speak="Prop. of Speaking Jurors", total="Prop. of all Jurors")) %>%
  ggplot() + 
  geom_bar(aes(x=group, y=prop, fill=Quantity), stat="identity", position="dodge") +   theme_bw()  +
  theme(text=element_text(size=20)) +
  xlab("Group") + ylab("Proportion of Sample") + 
  ggtitle("Composition of Total, Id'ed, and Speaking Jurors")



```


<!-- Figure S3: Preference Mentions and Group Verdicts -->

```{r, fig.width=20, fig.height=10}

# new table summarizing preference mentions
preftab <- tab2 %>% 
  filter(!is.na(jryscale)) %>%
  filter(scale=="scale") %>%
  filter(jryscale %in% c(0,1,2,3,4,5,6,7,8)) %>%
  group_by(jurynum, own_pref, jryscale) %>%
  summarize(mens=sample(pref_mentions, 1)) 

# reshape for plotting
preftab <- preftab %>%
  pivot_wider(id_cols=c(jurynum, jryscale), names_from=own_pref, names_prefix="pref", values_from=mens) %>%
  group_by(jryscale) %>%
  summarize(across(contains("pref"), ~mean(., na.rm=T)))
# create figure
a <- preftab %>%
  select(-prefNA) %>%
  pivot_longer(cols=contains("pref"), names_to="pref", values_to="count", names_prefix="pref") %>%
  ggplot() +
  geom_bar(aes(x=pref, y=count), stat="identity") +
  facet_wrap(~jryscale, nrow=1) + 
  theme_bw() + xlab("Preference") + ylab("Number of Mentions") + ggtitle("Mentions of Each Preference by Jury Verdict") +
  theme(text=element_text(size=40))

#pdf("pref_verdict.pdf", width=30, height=10)
a
#dev.off()

```

<!-- Table S3: Descriptive Statistics -->

```{r stats}
# summarize attributes 
sums <- tab1 %>%
  mutate(last_turn = total_turns - last_turn) %>%
  filter(jury_prop_words_attributed>.8) %>%
  group_by(round) %>%
  summarize(across(c(length, total_words_attr_round, total_pref_mentions, first_turn, last_turn, total_turns,
                     own_pref_mentions, other_pref_mentions, total_other_pref_mentions, fore_pref_mentions, 
                     fore_total_mentions,
                     distance, num_others_pref),
                   ~c(min(., na.rm=T),
                      quantile(., .25, na.rm=T),
                     mean(., na.rm=T), 
                      median(., na.rm=T),
                     quantile(., .75, na.rm=T),
                     max(., na.rm=T)
                      ))) %>%
  filter(round==1) %>%
  ungroup %>%
  select(-round) %>%
  t()
# recode for table
sums <- as.data.frame(sums)
colnames(sums) <- c("min", "q1", "mean", "median", "q3", "max")
sums$measure <- c("length", "total_words_attr_round", "total_pref_mentions", "first_turn", "last_turn", 
                  "total_turns", 
                  "own_pref_mentions", "other_pref_mentions", "total_other_pref_mentions",
                  "fore_pref_mentions", "fore_total_mentions",
                  "distance", "num_others_pref")
# calculate jury-transcript vars
jury_mentions=data.frame("min"=min(tab2$pref_mentions[tab2$round==1], na.rm=T),
                  "q1"=quantile(tab2$pref_mentions[tab2$round==1], .25, na.rm=T),
                  "mean"=mean(tab2$pref_mentions[tab2$round==1], na.rm=T),
                  "median"=median(tab2$pref_mentions[tab2$round==1], na.rm=T),
                  "q3"=quantile(tab2$pref_mentions[tab2$round==1], .75, na.rm=T),
                  "max"=max(tab2$pref_mentions[tab2$round==1], na.rm=T),
                  "measure"="jury_mentions")
sums <- rbind(sums, jury_mentions)
jury_mentions=data.frame("min"=min(tab2$total_mentions[tab2$round==1], na.rm=T),
                  "q1"=quantile(tab2$total_mentions[tab2$round==1], .25, na.rm=T),
                  "mean"=mean(tab2$total_mentions[tab2$round==1], na.rm=T),
                  "median"=median(tab2$total_mentions[tab2$round==1], na.rm=T),
                  "q3"=quantile(tab2$total_mentions[tab2$round==1], .75, na.rm=T),
                  "max"=max(tab2$total_mentions[tab2$round==1], na.rm=T),
                  "measure"="total_jury_mentions")
sums <- rbind(sums, jury_mentions)

# recode and print
sums <- sums %>%
  mutate(measure = recode(measure, length = "Speech length (words)",
                          total_words_attr_round = "Total Group Words (attr.)",
                          total_pref_mentions = "Indiv. Mentions of Any Pref",
                          total_jury_mentions = "Total Mentions, Any Pref (attr.)",
                          first_turn = "First Turn: Distance from Beginning",
                          last_turn = "Last Turn: Distance from End",
                          total_turns = "Total Length in Turns",
                          own_pref_mentions = "Own Mentions of Pref",
                          other_pref_mentions = "Others' Mentions of Pref",
                          total_other_pref_mentions = "Total Others' Mentions",
                          fore_pref_mentions = "Foreperson Mentions of Pref",
                          fore_total_mentions = "Forperson Total Mentions",
                          jury_mentions = "Group Mentions of Indiv Pref",
                          distance = "Absolute Distance from Group Median",
                          num_others_pref="N Sharing Pref"))
rownames(sums) <- NULL
sums <- sums[,c(7, 1:6)]                  

kable(sums, format = "latex", digits = 1, 
      col.names = c("Measure", "Min", "1st Quart.", "Mean", "Median", "3rd Quart.", "Max"))
```


<!-- Table S4: Interactions with Controls -->

```{r full_intx}
# repeat key models with all controls and race x composition interactions

mod1 <- lm_robust(log(length+1)~white*whites_cat+type+ordinal_pref+distance+num_others_pref+fore+log(total_words_attr_round-length+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(total_pref_mentions+1)~white*whites_cat+scale+ordinal_pref+distance+num_others_pref+fore+log(length+1),  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(first_turn+1)*-1)~white*whites_cat+type+ordinal_pref+distance+num_others_pref+fore+log(total_turns+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust((log(total_turns-last_turn+1)*-1)~white*whites_cat+type+ordinal_pref+distance+num_others_pref+fore+log(total_turns+1), 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod5 <- lm_robust(log(pref_mentions+1)~white*whites_cat+scale+ordinal_pref+distance+num_others_pref+log(total_mentions-pref_mentions+1),  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}

# export to latex
add_rows = data.frame(
term = c("SE Clusters", "N Clusters"),
mod1 = c("Group", mod1$nclusters),
mod2 = c("Group", mod2$nclusters),
mod3 = c("Group", mod3$nclusters),
mod4 = c("Group", mod4$nclusters),
mod5 = c("Group", mod5$nclusters)
)
attr(add_rows, "position") = c(26:29)

modelsummary(list("Speech Length"=mod1, "Prefs Mentioned"=mod2, "First Turn"=mod3, "Last Turn"=mod4, 
                  "Total Mentions of Pref"=mod5), output = "latex",
             coef_map = c("white"="Indiv. Race: White",
                "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites" = "White Indiv. x 5 Whites",
               "ordinal_pref"="Preference",
               "distance"="Pref. Distance",
               "num_others_pref"="Others Sharing Pref.",
               "fore"="Foreperson",
               "log(total_words_attr_round - length + 1)"="Total Group Words",
                "log(length + 1)"="Total Indiv. Words",
               "log(total_turns + 1)"="Total Turns",
               "log(total_mentions + 1)"="Total Group Pref. Mentions",
               "log(total_pref_mentions - own_pref_mentions + 1)"="Indiv. Mentions of Other Prefs",
               "log(total_other_pref_mentions + 1)"="Other Pref. Mentions",
               "log(fore_total_mentions + 1)"="Forep. Pref. Mentions",
               "log(total_mentions - pref_mentions + 1)"="Total Group Pref. Mentions"), 
             gof_omit="Std.Errors|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Interactions with Controls \\ \\label{si:intxn_controls}", add_rows = add_rows) %>%
  column_spec(2:6,width=".7in") %>%
      kable_styling(latex_options = c("hold_position", "full_width"))


#rm(mod1, mod2, mod3, mod4)
```


<!-- Table S5: Number of Others Sharing Preference -->

```{r}
# models of number of others sharing preference
mod1 <- lm_robust(num_others_pref~white+scale, 
                  data=tab2 %>% filter(round==1), 
                  clusters=jurynum,
                  fixed_effects=scenario)
mod2 <- lm_robust(num_others_pref~white+(own_pref>0)+scale, 
                  data=tab2 %>% filter(round==1), 
                  clusters=jurynum,
                  fixed_effects=scenario)


```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Scenario FEs", "SE Clusters", "N Clusters"),
mod1 = c( "X", "Group", mod1$nclusters),
mod2 = c( "X", "Group", mod2$nclusters))
attr(add_rows, "position") = c(7:10)

modelsummary(list("Model 1"=mod1, "Model 2"=mod2), output = "latex",
             coef_map = c("white"="Indiv. Race: White",
                          "own_pref > 0TRUE"="Preference $>$ 0",
               "scalescale"="Scale: Ratings"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars = TRUE, title = "Number of Others Sharing Preference \\label{tab:share_pref}", add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position")


rm(mod1, mod2)
```

<!-- Table S6: Models with Preference Distance Interactions -->

```{r}

# recode preference distance to categorical
tab1 <- tab1 %>% mutate(distance_b = case_when(distance==0~"none",
                                               distance %in% c(.5, 1)~".5 to 1",
                                               distance %in% c(1.5, 2, 2.5)~"1.5 to 2.5",
                                               distance>=3~"3+")) %>%
  mutate(distance_b = relevel(factor(distance_b), ref="none"))
tab2 <- tab2 %>% mutate(distance_b = case_when(distance==0~"none",
                                               distance %in% c(.5, 1)~".5 to 1",
                                               distance %in% c(1.5, 2, 2.5)~"1.5 to 2.5",
                                               distance>=3~"3+")) %>%
  mutate(distance_b = factor(distance_b)) %>%
  mutate(distance_b = relevel(distance_b, ref="none"))
tab1 <- tab1 %>% mutate(num_others_pref_b = case_when(num_others_pref==0~"0",
                                               num_others_pref %in% c(1)~"1",
                                               num_others_pref>=2~"2+")) %>%
  mutate(num_others_pref_b = relevel(factor(num_others_pref_b), ref="0"))
tab2 <- tab2 %>% mutate(num_others_pref_b = case_when(num_others_pref==0~"0",
                                               num_others_pref %in% c(1)~"1",
                                               num_others_pref>=2~"2+")) %>%
  mutate(num_others_pref_b = factor(num_others_pref_b)) %>%
  mutate(num_others_pref_b = relevel(num_others_pref_b, ref="0"))

# run models predicting mentions
mod1 <- lm_robust(log(pref_mentions+1)~white*distance_b+scale+num_others_pref,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust((log(own_pref_mentions+1))~white*distance_b+type+num_others_pref, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(other_pref_mentions+1))~white*distance_b+type+num_others_pref, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

mod4 <- lm_robust(log(pref_mentions+1)~white*num_others_pref_b+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod5 <- lm_robust((log(own_pref_mentions+1))~white*num_others_pref_b+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod6 <- lm_robust((log(other_pref_mentions+1))~white*num_others_pref_b+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: POC", "SE Clusters", "N Clusters"),
mod3 = c("", "Group", mod3$nclusters),
mod6 = c("", "Group", mod6$nclusters)
)
attr(add_rows, "position") = c(1, 14:15)

modelsummary(list("Other Mens"=mod3, 
                  "Other Mens"=mod6), output = "latex",
             coef_map = c("white"="Indiv. Race: White",
                          "distance_b.5 to 1"="Distance: .5 to 1",
                          "distance_b1.5 to 2.5"="Distance: 1.5 to 2.5",
                          "distance_b3+"="Distance: 3+",
                          "num_others_pref"="N. Sharing Pref.",
                          "white:distance_b.5 to 1"="White x Distance .5 to 1",
                          "white:distance_b1.5 to 2.5"="White x Distance 1.5 to 2.5",
                          "white:distance_b3+"="White x Distance 3+",
                          "num_others_pref_b1"="N Sharing Pref = 1",
                          "num_others_pref_b2+"="N Sharing Pref = 2",
                          "white:num_others_pref_b1"="White x 1 Sharing Pref.",
                          "white:num_others_pref_b2+"="White x 2+ Sharing Pref."
                                 ), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             estimate="{estimate} ({std.error}){stars}", statistic = NULL,
             title = "Models with Preference Distance Interactions \\ \\label{pref_intx1}", add_rows = add_rows) %>%
      kable_styling(latex_options = c("hold_position", "full_width")) %>%
  #column_spec(2:5,width=".7in") %>%
   row_spec(1, italic = T) 

```

<!-- Table S7: Matched Dissenter Analyses -->

```{r}
# filter to lone POC and all-white groups, dissenters
diss <- tab1 %>% filter(dissenter==TRUE&((white==1&whites==6)|(white==0&whites==5))) %>% filter(fore==0)
diss$nonwhite <- 1-diss$white
diss$init_distance <- diss$predelib_mean - diss$ordinal_pref

# match dissenters on distance/n sharing pref
diss_sub <- diss %>% filter(round==1&!is.na(num_others_pref))
match_mod <- matchit(formula = nonwhite~init_distance+num_others_pref,
                data = diss_sub,
                method = "cem",
                estimand = "ATT", 
                na.action="na.omit")
# run models with weights from matching
diss_sub$w <- match_mod$weights 
mod1 <- lm_robust(log(length+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod2 <- lm_robust(log(total_pref_mentions+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod3 <- lm_robust((log(first_turn+1)*-1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod4 <- lm_robust((log(total_turns-last_turn+1)*-1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod5 <- lm_robust(log(own_pref_mentions+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod6 <- lm_robust(log(other_pref_mentions+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")
mod7 <- lm_robust(log(fore_pref_mentions+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario, 
          weights=w, clusters=jurynum, se_type="stata")


```


```{r}
# repeat for jury transcript data
diss <- tab2 %>% filter(dissenter==TRUE&((white==1&whites==6)|(white==0&whites==5)))
diss$nonwhite <- 1-diss$white
diss$init_distance <- diss$predelib_mean - diss$ordinal_pref

# round 1, scale
diss_sub <- diss %>% filter(round==1)
match_mod <- matchit(formula = nonwhite~init_distance+num_others_pref,
                data = diss_sub,
                method = "cem",
                estimand = "ATT", 
                na.action="na.omit")
#summary(match_mod)
diss_sub$w <- match_mod$weights 
mod3b <- lm_robust(log(pref_mentions+1)~nonwhite+scale, 
          data= diss_sub, fixed_effects = scenario,
          weights=w, clusters=jurynum, se_type="stata")
```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("SE Clusters", "N Clusters"),
mod1 = c("Group", mod1$nclusters),
mod2 = c("Group", mod2$nclusters),
mod3 = c("Group", mod3$nclusters),
mod4 = c("Group", mod4$nclusters),
mod3b = c("Group", mod3b$nclusters),
mod5 = c("Group", mod5$nclusters),
mod6 = c("Group", mod6$nclusters),
mod7 = c("Group", mod7$nclusters)
)
attr(add_rows, "position") = c(9:12)

modelsummary(list("Speech Length"=mod1, "Total Prefs"=mod2, "First Turn"=mod3, "Last Turn"=mod4, 
                  "Total Mens"=mod3b, "Own Mens"=mod5, "Other Mens"=mod6, "Fore Mens"=mod7), output = "latex",
             coef_map = c("nonwhite"="Indiv. Race: Nonwhite",
                          "scalescale"="Scale: Rating"),
             gof_omit="Std.Errors",
             stars = TRUE, title = "Matched Dissenter Analyses", add_rows = add_rows) %>%
      kable_styling(latex_options = c("hold_position", "full_width"))

```


<!-- Table S8: Mentions of Prefs. > 3pts from Focal Member's -->

```{r}
# predict mentions of far preferences
mod1 <- lm_robust(log(far_mentions+1)~white+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(far_mentions+1)~white*whites_cat+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(far_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref+num_others_far,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust(log(far_mentions+1)~white+scale+ordinal_pref+distance+num_others_pref+num_others_far+log(total_mentions-pref_mentions+1)+predelib_median,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)
```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(14, 19, 23:25)

modelsummary(list("Base Model"=mod1, "Preference Control"=mod3, "Endog. Controls"=mod4, "Interaction"=mod2), 
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
               "distance"="Pref. Distance",
               "num_others_pref" = "Others Sharing Pref",
               "num_others_far" = "Others w. Far Prefs",
               "log(total_mentions - pref_mentions + 1)"="Total Group Mentions",
               "predelib_median"="Predelib. Median",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites"="White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Mentions of Prefs. >3pts from Focal Member's \\label{tab:juror_far}", 
             add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(14, italic = T) %>%
      row_spec(19, italic = T)

```

<!-- Table S9: White Group Members' Mentions of Participant Preference -->

    ```{r}
mod1 <- lm_robust(log(white_mens+1)~white+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(white_mens+1)~white*whites_cat+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust(log(white_mens+1)~white+scale+ordinal_pref+distance+num_others_pref,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust(log(white_mens+1)~white+scale+ordinal_pref+distance+num_others_pref+fore+log(total_white_mens+1),  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: Less than 5 whites", "Omitted: White x Less than 5 whites", "Scenario and Scale FEs", "SE Clusters", "N Clusters"),
mod1 = c("", "", "X", "Group", mod1$nclusters),
mod3 = c("", "", "X", "Group", mod3$nclusters),
mod4 = c("", "", "X", "Group", mod4$nclusters),
mod2 = c("", "", "X", "Group", mod2$nclusters)
)
attr(add_rows, "position") = c(11, 14, 17:20)

modelsummary(list("Base Model"=mod1,"Preference Control"=mod3, "Endog. Control"=mod4, "Interaction"=mod2),
             output = "latex",
             coef_map = c("white"="Indiv. Race: White",
               "ordinal_pref"="Preference",
               "log(total_white_ments + 1)"="Total Pref. Mentions",
                              "distance"="Pref. Distance",
               "num_others_pref"="Others Sharing Pref.",
               "log(length + 1)"="Total Indiv. Speech",
               "fore"="Foreperson",
               "whites_cat5 whites"="5 Whites", 
               "whites_cat6 whites"="6 Whites", 
               "white:whites_cat5 whites" = "White x 5-White Group"), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "White Group Members' Mentions of Participant Preference \\label{tab:white_pref}", add_rows = add_rows) %>%
      kable_styling(latex_options = "hold_position") %>%
  column_spec(2:5,width=".7in") %>%
      row_spec(11, italic = T) %>%
      row_spec(14, italic = T)

```


<!-- Table S10: Models with Demographic Controls -->

```{r all_controls}
# recode demographics
tab1$educ <- factor(tab1$educ, levels=c("HS or less", "Some coll.", "BA or more"))
tab1$educ <- relevel(tab1$educ, ref="HS or less")

tab2$educ <- factor(tab2$educ, levels=c("HS or less", "Some coll.", "BA or more"))
tab2$educ <- relevel(tab2$educ, ref="HS or less")

tab1$income <- relevel(factor(tab1$income), ref="30k or less")
tab2$income <- relevel(factor(tab2$income), ref="30k or less")

tab1$age <- relevel(factor(tab1$age), ref="18-39")
tab2$age <- relevel(factor(tab2$age), ref="18-39")

# run models with all controls
mod1 <- lm_robust(log(length+1)~white+educ+income+age+sex+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(total_pref_mentions+1)~white+educ+income+age+sex+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(first_turn+1)*-1)~white+educ+income+age+sex+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust((log(total_turns-last_turn+1)*-1)~white+educ+income+age+sex+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod5 <- lm_robust(log(pref_mentions+1)~white+educ+income+age+sex+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}
# export to latex
add_rows = data.frame(
term = c("Omitted: POC", "Omitted: HS grad or less", "Omitted: Income textless 30k", "Omitted: Age 18-39", "Omitted: Sex = F", "SE Clusters", "N Clusters"),
mod1 = c("", "","","","", "Group", mod1$nclusters),
mod2 = c("", "","","","", "Group", mod2$nclusters),
mod3 = c("", "","","","", "Group", mod3$nclusters),
mod4 = c("", "","","","", "Group", mod4$nclusters),
mod5 = c("", "","","","", "Group", mod5$nclusters)
)
attr(add_rows, "position") = c(1, 4, 9, 14, 19, 22:23)

modelsummary(list("Speech Length"=mod1, "Prefs Mentioned"=mod2, "First Turn"=mod3, 
                  "Last Turn"=mod4, 
                  "Mens. of Pref"=mod5), output = "latex",
             coef_map = c("white"="Indiv. Race: White",
                          "educSome coll."="Some college",
                          "educBA or more"="BA or more",
                          "income30-50k"="Income 30-50k",
                          "incomemore than 50k"="Income 50k+",
                          "age40-59"="Age 40-59",
                          "age60+"="Age 60+",
                          "sexM"="Sex: M"
                                 ), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Models with Demographic Controls \\ \\label{ed_controls}", add_rows = add_rows) %>%
      kable_styling(latex_options = c("hold_position", "full_width")) %>%
  column_spec(2:5,width=".7in") %>%
   row_spec(1, italic = T) %>%
   row_spec(4, italic = T) %>%
  row_spec(9, italic = T) %>%
  row_spec(14, italic = T) %>%
  row_spec(19, italic = T) 


#rm(mod1, mod2, mod3, mod4)
```


<!-- Table S11: Models with Hispanic Indicator -->

```{r hisp_ind}

tab1$hisp <- ifelse(tab1$ethnic==4, 1, 0)
tab2$hisp <- ifelse(tab2$ethnic==4, 1, 0)

mod1 <- lm_robust(log(length+1)~hisp+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod2 <- lm_robust(log(total_pref_mentions+1)~hisp+scale,  
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod3 <- lm_robust((log(first_turn+1)*-1)~hisp+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod4 <- lm_robust((log(total_turns-last_turn+1)*-1)~hisp+type, 
          data=tab1 %>% filter(round==1&jury_prop_words_attributed>.8), 
          clusters=jurynum,
          fixed_effects = scenario)
mod5 <- lm_robust(log(pref_mentions+1)~hisp+scale,  
          data=tab2 %>% filter(round==1), 
          clusters=jurynum,
          fixed_effects = scenario)

```

```{r, results='asis'}
add_rows = data.frame(
term = c( "SE Clusters", "N Clusters"),
mod1 = c( "Group", mod1$nclusters),
mod2 = c( "Group", mod2$nclusters),
mod3 = c( "Group", mod3$nclusters),
mod4 = c( "Group", mod4$nclusters),
mod5 = c( "Group", mod5$nclusters)
)
attr(add_rows, "position") = c(3:4)

modelsummary(list("Speech Length"=mod1, "Prefs Mentioned"=mod2, "First Turn"=mod3, 
                  "Last Turn"=mod4, 
                  "Mens. of Pref"=mod5), output = "latex",
             coef_map = c("hisp"="Indiv. Race: Hispanic"
                                 ), 
             gof_omit="Std.Errors|^(?!.*Adj)|AIC|BIC|RMSE",
             stars=c('*' = .05, "**"=.01, "***"=.001),
             title = "Models with Hispanic Indicator \\ label{hisp}", add_rows = add_rows) %>%
      kable_styling(latex_options = c("hold_position", "full_width")) %>%
  column_spec(2:5,width=".7in") 

```



<!-- Table S12: Negative Binomial Models -->

``` {r}
p_load(MASS)

tab1_reduce <- tab1 %>%
  filter(round==1&jury_prop_words_attributed>.8)
tab1_reduce$last_turn2 <- tab1_reduce$total_turns-tab1_reduce$last_turn

tab2_reduce <- tab2 %>%
  filter(round==1)

nb_mod1 <- glm.nb(length~white+type + as.factor(scenario), 
          data=tab1_reduce)
nb_mod2 <- glm.nb(total_pref_mentions~white+scale+as.factor(scenario),  
          data=tab1_reduce)
nb_mod3 <- glm.nb(first_turn~white+type+as.factor(scenario), 
          data=tab1_reduce)
nb_mod4 <- glm.nb(last_turn2~white+type+as.factor(scenario), 
          data=tab1_reduce)
nb_mod5 <- glm.nb(pref_mentions~white+scale+as.factor(scenario),  
          data=tab2_reduce)

# Identify non-missing rows for each model
rows_nb_mod1 <- complete.cases(tab1_reduce[, c("length", "white", "type", "scenario")])
rows_nb_mod2 <- complete.cases(tab1_reduce[, c("total_pref_mentions", "white", "scale", "scenario")])
rows_nb_mod3 <- complete.cases(tab1_reduce[, c("first_turn", "white", "type", "scenario")])
rows_nb_mod4 <- complete.cases(tab1_reduce[, c("last_turn2", "white", "type", "scenario")])
rows_nb_mod5 <- complete.cases(tab2_reduce[, c("pref_mentions", "white", "scale", "scenario")])

# Subset the clustering variable
cluster_var_nb_mod1 <- tab1_reduce$jurynum[rows_nb_mod1]
cluster_var_nb_mod2 <- tab1_reduce$jurynum[rows_nb_mod2]
cluster_var_nb_mod3 <- tab1_reduce$jurynum[rows_nb_mod3]
cluster_var_nb_mod4 <- tab1_reduce$jurynum[rows_nb_mod4]
cluster_var_nb_mod5 <- tab2_reduce$jurynum[rows_nb_mod5]

# Ensure lengths match
num_clusters_tab1_reduce <- length(unique(tab1_reduce$jurynum))
num_clusters_tab2 <- length(unique(tab2_reduce$jurynum))

add_rows = data.frame(
term = c("Scenario and Scale FEs", "SE Clusters", "N Clusters"),
nb_mod1 = c("X", "Group", num_clusters_tab1_reduce),
nb_mod2 = c("X", "Group", num_clusters_tab1_reduce),
nb_mod3 = c("X", "Group", num_clusters_tab1_reduce),
nb_mod4 = c("X", "Group", num_clusters_tab1_reduce),
nb_mod5 = c("X", "Group", num_clusters_tab2)
)
attr(add_rows, "position") = c(3:5)

# Create a list of models
models <- list(
  "Speech Length" = nb_mod1, 
  "Prefs. Mentioned" = nb_mod2, 
  "First Turn" = nb_mod3, 
  "Last Turn" = nb_mod4, 
  "Mens. of Pref." = nb_mod5
)

# Create a list of models
models <- list(
  "Speech Length" = nb_mod1, 
  "Prefs. Mentioned" = nb_mod2, 
  "First Turn" = nb_mod3, 
  "Last Turn" = nb_mod4, 
  "Mens. of Pref." = nb_mod5
)

# Compute cluster-robust variance-covariance matrices
vcov_list <- list(
  "Length of Speech" = vcovCR(nb_mod1, cluster = cluster_var_nb_mod1, type = "CR2"),
  "Any Preference" = vcovCR(nb_mod2, cluster = cluster_var_nb_mod2, type = "CR2"),
  "First Turn" = vcovCR(nb_mod3, cluster = cluster_var_nb_mod3, type = "CR2"),
  "Last Turn" = vcovCR(nb_mod4, cluster = cluster_var_nb_mod4, type = "CR2"),
  "Preference Mentions" = vcovCR(nb_mod5, cluster = cluster_var_nb_mod5, type = "CR2")
)



# Create the model summary with precomputed cluster-robust standard errors
modelsummary(
  models,
  vcov = vcov_list,  
  coef_omit = "^(?!white)",
  coef_map = c("white" = "Indiv. Race: White"),  
  gof_omit = "Std.Errors|AIC|BIC|Num.Obs",
  stars = TRUE,
  title = "Negative Binomial Regressions \\label{tab:neg_bin}",
  output = "latex",
  add_rows = add_rows
) %>%
      kable_styling(latex_options = c("hold_position", "full_width"))

```